from manim import *



class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(6*2+1):       
            dot1=Dot([-50,5*(i-6),0]).set_opacity(0.5)
            dot2=Dot([50,5*(i-6),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(10*2+1):        
            dot3=Dot([(i-10)*5,-30,0]).set_opacity(0.5)
            dot4=Dot([(i-10)*5,30,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
         #镜头跟进效果
        self.camera.frame.save_state()
         #中心主题+框框标记
        text1 = Tex(r"\text{微分不等式}",color=PINK
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,5,0])
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=23,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([-30, 5, 0])
        self.play(Create(rectangle),Create(text1),FadeIn(dot1),FadeIn(dot2),FadeIn(dot3))
       





        #百分之90+，动态更新效果

       # 创建一个 DecimalNumber 对象，初始值为 0
        number = DecimalNumber(0, num_decimal_places=0, color=YELLOW)

        # 设置数字的位置
        number.next_to(rectangle,UP,buff=4).scale(20)

        # 添加到场景中
        self.add(number)
        





        #箭头引出
        arrow = Arrow(start=[-18,7.5,0],end=[-10,15,0], color=RED
                       , stroke_width=20, tip_length=1)
        #文本2
        text2 = Tex(r"\text{单调性（具体型）}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,15,0])
        #箭头1引出
        arrow1 = Arrow(start=[-18,6,0],end=[-10,10,0], color=RED
                       , stroke_width=20, tip_length=1)
        text3 = Tex(r"\text{单调性（抽象型）}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,10,0])

        #箭头2引出 
        arrow2 = Arrow(start=[-18,5,0],end=[-10,5,0], color=RED
                       , stroke_width=20, tip_length=1)
        text4 = Tex(r"\text{凹凸性}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-2.5,5,0])

        #箭头3引出
        arrow3 = Arrow(start=[-18,3,0],end=[-10,-5,0], color=RED
                       , stroke_width=20, tip_length=1)
        #文本5 
        text5= Tex(r"\text{利用中值定理}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,- 5,0])
        
        
        # 播放增加动画
        self.play(ChangeDecimalToValue(number, 99),Create(arrow),Create(arrow1),Create(arrow2),Create(arrow3) ,run_time=1)  # 将数字从 0 变化到 99，持续时间为 3 秒
        self.play(FadeOut(number),Create(text2),Create(text3),Create(text4),Create(text5))
        
         #箭头引出
        arrow4 = Arrow(start=[10,17,0],end=[17,22,0], color=RED
                       , stroke_width=20, tip_length=1)
        #文本2
        text6 = Tex(r"\text{直接构造}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([22,22,0])
         #箭头引出
        arrow5 = Arrow(start=[10,15,0],end=[17,15,0], color=RED
                       , stroke_width=20, tip_length=1)
        #文本2
        text7 = Tex(r"\text{变形构造}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([22,15,0])
          #箭头引出
        arrow6 = Arrow(start=[10,13,0],end=[17,10,0], color=RED
                       , stroke_width=20, tip_length=1)
        #文本2
        text8 = Tex(r"\text{巧妙构造}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([22,10,0])
         #箭头引出
        arrow7 = Arrow(start=[3,5,0],end=[10,5,0], color=RED
                       , stroke_width=20, tip_length=1)
        #文本2
        text9 = Tex(r"\text{琴生不等式}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([17,5,0])
         #箭头引出
        arrow8 = Arrow(start=[10,-3,0],end=[15,0,0], color=RED
                       , stroke_width=20, tip_length=1)
        #文本2
        text10 = Tex(r"\text{拉格朗日}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([21,0,0])
        arrow9 = Arrow(start=[10,-3,0],end=[15,-10,0], color=RED
                       , stroke_width=20, tip_length=1)
        #文本2
        text11 = Tex(r"\text{柯西}"   
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,-10,0])



        self.play(Create(arrow4),Create(text6),Create(arrow5)
                  ,Create(text7),Create(arrow6)
                  ,Create(text8),Create(text9)
                  ,Create(text10),Create(arrow9)
                  ,Create(text11),Create(arrow8)
                  ,Create(arrow7))
        self.wait()

        rectangle2=Rectangle(color=BLUE,fill_opacity=0.0,width=80,height=40
                            ,stroke_color=YELLOW,stroke_width=20)
        rectangle2.move_to([-5,5,0])
        self.play(Create(rectangle2))
        text12 = Tex(r"\text{解题思路结构化}" ,color=GREEN  
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle2,DOWN,buff=2)
        self.play(Create(text12))
        rectangle1=Rectangle(color=BLUE,fill_opacity=0.0,width=15,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle1.move_to([22,15,0])
        self.play(Create(rectangle1),self.camera.frame.animate.scale(0.6).move_to([22,15,0]))